// 人员下拉框指令
define('userSelectDirective', ['angular'], function (angular) {
    var m = angular.module('directives');
    m.directive('userSelect', ['$filter','userServers',function ($filter,userServers) {
        return {
            restrict: 'AE',
            templateUrl: 'js/templates/userSelect.html',
            replace: true,
            scope:{
                companyId:"@?",
                currentId:"=?"
            },
            controller:['$scope','$rootScope',function($scope,$rootScope){
                if(!$rootScope.userList){
                    userServers.userList().then(function (data) {
                        $rootScope.userList=data;
                        if(!$scope.companyId){
                            $scope.user = $rootScope.userList;
                        }else{
                            $scope.user = $filter('companySelectUserListFilter')($rootScope.userList,$scope.companyId);
                        }
                    });
                }else{
                    $scope.user = $rootScope.userList;
                }
                $scope.$watch('companyId',function(newValue,oldValue, scope){
                    if(newValue!==""){
                        $scope.user = $filter('companySelectUserListFilter')($rootScope.userList,newValue);
                    }else{
                        $scope.user = $rootScope.userList;
                    }
                    // $scope.currentId="";
                });
            }]
        };
    }]);
});